package org.example.schdule;

import org.example.pojo.domain.Artifact;
import org.example.service.ArtifactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ArtifactStatusCheckTask {

    @Autowired
    private ArtifactService artifactService;

    @Scheduled(cron = "0 0 0 * * ?") // 每天午夜执行
    public void ArtifactLoanedCheck(){
        List<Integer> expireArtifactId = artifactService.checkExpire();
        for (Integer artifactId :expireArtifactId){
            Artifact artifact = new Artifact();
            artifact.setArtifactId(artifactId);
            artifact.setStatus("available");
            artifactService.updateArtifact(artifact);
            artifactService.removeShowById(artifactId);
        }
    }

}
